﻿using HYRN.Common.ConvertUtilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Admin.NET.Common.Base.EdgeConvert
{
    public static class DateTimeUtil
    {

        public static DateTime GetNowDayBeginTime()
        {
            return DateTime.Now.ToString("yyyy-MM-dd 00:00:00").ObjToDate();
        }


        #region 时间戳[10|13]转为C#格式时间  

        public static DateTime StampToDateTimeMilliseconds(long stamp)
        {
            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区 
            DateTime dt = startTime.AddMilliseconds(stamp);
            return dt;
        }

        public static DateTime StampToDateTime(long stamp)
        {
            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区 
            DateTime dt = startTime.AddSeconds(stamp);
            return dt;
        }


        #endregion
        /// <summary>
        /// 获取时间戳
        /// </summary>
        /// <returns></returns>
        public static long GetTimeStampMilliseconds()
        {
            TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
            return Convert.ToInt64(ts.TotalMilliseconds);
        }


        public static long GetTimeStamp(DateTime? myTime)
        {
            if (myTime == null) { return 0; }

            TimeSpan ts = Convert.ToDateTime(myTime) - new DateTime(1970, 1, 1, 0, 0, 0, 0);
            return Convert.ToInt64(ts.TotalSeconds);
        }



        public static long GetTimeStamp()
        {
            TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
            return Convert.ToInt64(ts.TotalSeconds);
        }


        public static string GetWeekName()
        {
            string[] Day = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
            string week = Day[Convert.ToInt32(DateTime.Now.DayOfWeek.ToString("d"))].ToString();
            return week;
        }


    }
}
